package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHoc;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocService;
import com.lb.jwitter.service.TblQLDTTXADMKhoa;
import com.lb.jwitter.service.TblQLDTTXADMKhoaService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAChuongTrinhHocUpdateAction{
    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
 }

    public String getTen() {
       return ten;
 }

    private String ngayApDung; 
    public void setNgayApDung(String ngayApDung) {
       this.ngayApDung = ngayApDung;
 }

    public String getNgayApDung() {
       return ngayApDung;
 }

    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
 }

    public String getGhiChu() {
       return ghiChu;
 }

    private int khoaId; 
    public void setKhoaId(int khoaId) {
       this.khoaId = khoaId;
 }

    public int getKhoaId() {
       return khoaId;
 }

    private TblQLDTTXAChuongTrinhHoc tblQLDTTXAChuongTrinhHoc; 
    public void setTblQLDTTXAChuongTrinhHoc (TblQLDTTXAChuongTrinhHoc tblQLDTTXAChuongTrinhHoc) {
        this.tblQLDTTXAChuongTrinhHoc = tblQLDTTXAChuongTrinhHoc;
 }

    private TblQLDTTXAChuongTrinhHocService tblQLDTTXAChuongTrinhHocService; 

    private TblQLDTTXADMKhoaService tblQLDTTXADMKhoaService; 

	private int preUpdate(Message msg, TblQLDTTXAChuongTrinhHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAChuongTrinhHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_ChuongTrinhHoc", "sua")){ 
        return "noprivilege"; 
    }        tblQLDTTXAChuongTrinhHocService = (TblQLDTTXAChuongTrinhHocService) context.getBean("tbl_QLDTTXA_ChuongTrinhHocClient"); 
        tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient"); 

        msg = new Message(); 
        tblQLDTTXAChuongTrinhHoc = tblQLDTTXAChuongTrinhHocService.gettblQLDTTXAChuongTrinhHoc(new Long(id)); 
        tblQLDTTXAChuongTrinhHoc.setTen(ten); 
       DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
       Date dd = df.parse(ngayApDung); 
       GregorianCalendar c = new GregorianCalendar(); 
       c.setTime(dd);
       XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
        tblQLDTTXAChuongTrinhHoc.setNgayApDung(d); 
        tblQLDTTXAChuongTrinhHoc.setGhiChu(ghiChu); 
        tblQLDTTXAChuongTrinhHoc.setKhoaId(tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(new Long(khoaId))); 
        preUpdate(msg,tblQLDTTXAChuongTrinhHoc); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAChuongTrinhHocService.updatetblQLDTTXAChuongTrinhHoc(tblQLDTTXAChuongTrinhHoc); 
           postUpdate(msg, tblQLDTTXAChuongTrinhHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_ChuongTrinhHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
